package com.chanjiedata.changbs.module.createcard;

import android.graphics.Color;
import android.os.Bundle;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.chanjiedata.changbs.R;
import com.chanjiedata.changbs.base.BaseActivity;
import com.chanjiedata.changbs.utlis.StatusBarUtil;
import com.google.android.material.tabs.TabLayout;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

public class CreateShopListActivity extends BaseActivity {
    Unbinder unbinder;
    @BindView(R.id.back_tv)
    TextView backTv;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.tab_layout)
    TabLayout tabLayout;
    @BindView(R.id.view_pager)
    ViewPager viewPager;

    private CreateShopFragment fragment_one;
    private CreateShopFragment fragment_two;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_create_shop_list);
        unbinder = ButterKnife.bind(this);
        StatusBarUtil.setStatusBarLightMode(this, Color.parseColor("#ffffff"), true);
        backTv.setOnClickListener(view -> finish());
        initView();
        tvTitle.setText("制卡");
    }


    protected void initView() {
        String[] titles = {"待制卡片", "已制卡片"};
        List<Fragment> fragmentList = new ArrayList<>();
        fragmentList.add(fragment_one = CreateShopFragment.NewInstance(0));
        fragmentList.add(fragment_two = CreateShopFragment.NewInstance(1));
        viewPager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                return fragmentList.get(position);
            }

            @Override
            public int getCount() {
                return fragmentList.size();
            }

            @Override
            public CharSequence getPageTitle(int position) {
                return titles[position];
            }
        });
        //设置图标
        tabLayout.setupWithViewPager(viewPager);
        int page = getIntent().getIntExtra("page", 0);
        if (page != 0) {
            viewPager.setCurrentItem(page);
        }
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        unbinder.unbind();
    }
}
